<script setup lang="ts">
	import { postEditUser } from '@/api/User'
	import type { UserProfile } from '@/types/index'
	import { ref } from 'vue'
	import { useMemberStore } from '../../store';
	const store = useMemberStore()
	const UserInfo = ref<UserProfile>(store.profileSummary)
	const showModal = async (text : string) => {
		uni.showModal({
			title: `修改${text}`,
			content: UserInfo.value.name,
			editable: true,
			success: async (res) => {
				console.log(res)
				if (res.confirm) {
					await postEditUser({ name: res.content })
					UserInfo.value.name = res.content
				}
			},
		})
	}
</script>

<template>
	<view class="viewport">
		<view class="list">
			<view class="item" @click="showModal('昵称')">
				<view>昵称</view>
				<view>{{UserInfo.name || '未设置'}}<text class="icon icon-jiantou2" /></view>
			</view>
			<view class="item">
				<view>手机号</view>
				<view>{{UserInfo.phone || '未设置'}}</view>
			</view>
			<view class="item">
				<view>机构名称</view>
				<view>{{UserInfo.companyName || '未设置'}} </view>
			</view>
		</view>

		<!-- #ifdef MP-WEIXIN -->
		<!-- <view class="list">
			<button hover-class="none" class="item arrow" open-type="openSetting">授权管理</button>
			<button hover-class="none" class="item arrow" open-type="feedback">问题反馈</button>
			<button hover-class="none" class="item arrow" open-type="contact">联系我们</button>
		</view> -->
		<!-- #endif -->
		<!-- <view class="list">
			<navigator hover-class="none" class="item arrow" url=" " @click="showModal('手机号')">手机号</navigator>
		</view>
		<view class="list">
			<navigator hover-class="none" class="item arrow" url=" "  @click="showModal('机构名称')">机构名称</navigator>
		</view> -->

	</view>
</template>

<style lang="scss">
	page {
		background-color: #f4f4f4;
	}

	.viewport {
		padding: 20rpx;
	}

	/* 列表 */
	.list {
		width: 100%;
		padding: 0 20rpx;
		background-color: #fff;
		// margin-bottom: 20rpx;
		border-radius: 10rpx;

		.item {
			line-height: 90rpx;
			padding-left: 10rpx;
			font-size: 30rpx;
			color: #333;
			border-top: 1rpx solid #ddd;
			position: relative;
			text-align: left;
			border-radius: 0;
			background-color: #fff;
			display: flex;
			justify-content: space-between;

			&::after {
				width: auto;
				height: auto;
				left: auto;
				border: none;
			}

			&:first-child {
				border: none;
			}

			&::after {
				right: 5rpx;
			}
		}

		.arrow::after {
			content: '\e6c2';
			position: absolute;
			top: 50%;
			color: #ccc;
			font-family: 'erabbit' !important;
			font-size: 32rpx;
			transform: translateY(-50%);
		}
	}

	/* 操作按钮 */
	.action {
		text-align: center;
		line-height: 90rpx;
		margin-top: 40rpx;
		font-size: 32rpx;
		color: #333;

		.button {
			background-color: #fff;
			margin-bottom: 20rpx;
			border-radius: 10rpx;
		}
	}
</style>